import os
from zai import ZhipuAiClient


def get_api_key() -> str:
    """Get API key from environment variables"""
    api_key = os.getenv("ZHIPUAI_API_KEY")
    if not api_key:
        raise ValueError("ZHIPUAI_API_KEY环境变量未设置，请检查客户端配置")
    return api_key


api_key = get_api_key()
client = ZhipuAiClient(api_key=api_key)
response = client.chat.completions.create(
    model="glm-4.5v",  # 填写需要调用的模型名称
    messages=[
        {
            "content": [
                {
                    "type": "text",
                    "text": "请讲个笑话，关于男人和女人的",
                },
            ],
            "role": "user",
        }
    ],
    thinking={"type": "enabled"},
)
print(response.choices[0].message.content)
